"""
演示元组的定义和操作
"""
# 定义元组
t1 = (1,"HZH",True)
# 定义空列表
t2 = ()
t3 = tuple()
print(f"t1的类型是:{type(t1)}",t1)
print(f"t1的类型是:{type(t2)}",t2)
print(f"t1的类型是:{type(t3)}",t3)

# 定义单个元素的元组
t4 = ("HZH")
print(f"t4的类型是:{type(t4)}","内容是：",t4)
# 运行结果：
# t4的类型是:<class 'str'> 内容是： HZH
t4 = ("HZH",)
print(f"t4的类型是:{type(t4)}","内容是：",t4)
# 运行结果：
# t4的类型是:<class 'tuple'> 内容是： ('HZH',)

# 元组的嵌套
t5 = ((1,2,3),(4,5,6))
print(f"t5的类型是:{type(t5)},内容是:{t5}")

# 下标索引取对应值
num = t5[1][2]
print(f"从t5元组中取出的元素是：{num}")

# 用index（）语句查找元组中元素下标
t6 = ("HZH","ZJY","Python")
index = t6.index("Python")
print(f"在t6中元素“Python”的下标是：{index}")

# count（）统计某一元素数量
t7 = ("HZH","ZJY","Python","Python","Python","Python")
count = t7.count("Python")
print(f"t7元组中元素“Python”的数量是：{count}")

# len() 统计元组中元素的数量
t8 = ("HZH","ZJY","Python","Python","Python","Python")
num = len(t8)
print(f"在元组t8中一共有{num}个元素")

# while循环遍历元组
index = 0
while index < len(t8):
    print(f"元组的元素有：{t8[index]}")
    index += 1

# for循环遍历元组
for element in t8:
    print(f"元组中的元素有：{element}")

# 尝试修改元组元素
t9 = ("HZH","ZJY","Python",["Python","Python","Python"])
print(t9)
t9[3][0] = "年薪过万"
print(t9)